SlideShare a Scribd company logo
1 of 7
Struts 2
Spring and JPA / Hibernate
        Integration



                      KrazyKoder.com
Why use Spring with Struts ?
   It is a lightweight dependency injection and
    aspect-oriented container and framework.

   Promote Loose Coupling through Dependancy
    Injection.

   Most popular technology for managing creation
    of objects in a Java application.

   Has its own MVC application framework.
                                           KrazyKoder.com
Adding Spring to Struts2 Contd…..
   Add the Spring plug-in to application.

   Add
    org.springframework.web.context.ContextLoaderListener
    to web.xml in listener tag.

   ApplicationContext.xml file will be used for doing the
    Spring bean configuration.

   Spring Provides the autowiring mechanism through
    which it automatically inject dependencies without
    explicitly declaring the wiring in applicationContext.xml

   Autowiring can be done by name, type, constructor or
    auto.                                     KrazyKoder.com
Adding Spring to Struts2 …..Contd.
   All objects which spring manages are called “Spring Beans” and all spring
    beans are created as Singleton.

   Add bean to applicationContext.xml file and change scope of bean to
    Prototype.

   ID in first bean to identify the bean, much like a reference is used to identify
    an object in Java code.

   Property tag looks for setter method with the same name as the property
    tag’s name attribute.

   Value to inject into this setter is specified with the ref attribute

   Ex : <bean id="portfolioService"
    class="manning.chapterNine.utils.PortfolioServiceJPAImpl"/>
    <bean id="springManagedLoginAction” class="manning.chapterNine.Login“
    scope="prototype">
    <property name="portfolioService" ref="portfolioService"/>
                                                               KrazyKoder.com
    </bean>
Adding JPA with Struts 2?
   This technology, wrapped around Hibernate.

   Coding to the JPA works a lot like coding to native
    Hibernate.

   Interface-based architecture gives you the ability to
    switch out the vendor supplying the underlying
    implementation.

   Shows how to use the well-respected Spring support for
    JPA to make management of the JPA all that much
    easier.

   Main entry point into the JPA is EntityManager. This
    object manages all persistent entities.     KrazyKoder.com
Adding JPA with Struts 2?
   Declare a bean postprocessor that checks all the beans
    managed by Spring for persistence-related annotations

   EntityManagerFactory managed by Spring encapsulates
    most of the details of persistence unit.

   Main entry point into configuring persistence unit is the
    persistence.xml file.
    /WEB-INF/classes/METAINF/persistence.xml

   Through JPA we can use Java annotations to map java
    classes to database.

                                                  KrazyKoder.com
Done!



   Click the   icon at the bottom to proceed!




                                       KrazyKoder.com

More Related Content

What's hot

Introduction to springs and controlers
Introduction to springs and controlersIntroduction to springs and controlers
Introduction to springs and controlers
patil027
 

What's hot (20)

Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
TechEvent Eclipse Microprofile
TechEvent Eclipse MicroprofileTechEvent Eclipse Microprofile
TechEvent Eclipse Microprofile
 
Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6Integrating Wicket with Java EE 6
Integrating Wicket with Java EE 6
 
Akka java-es-cqrs
Akka java-es-cqrsAkka java-es-cqrs
Akka java-es-cqrs
 
Spring 4 en spring data
Spring 4 en spring dataSpring 4 en spring data
Spring 4 en spring data
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Mule security - ldap for spring security
Mule  security - ldap for spring securityMule  security - ldap for spring security
Mule security - ldap for spring security
 
Infinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactiveInfinum iOS Talks #4 - Making our VIPER more reactive
Infinum iOS Talks #4 - Making our VIPER more reactive
 
Identifing Listeners and Filters
Identifing Listeners and FiltersIdentifing Listeners and Filters
Identifing Listeners and Filters
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
7. signal r aspdotnet-mvc5-slides
7. signal r aspdotnet-mvc5-slides7. signal r aspdotnet-mvc5-slides
7. signal r aspdotnet-mvc5-slides
 
1. introduction and prerequisites aspdotnet-mvc5-slides
1.  introduction and prerequisites aspdotnet-mvc5-slides1.  introduction and prerequisites aspdotnet-mvc5-slides
1. introduction and prerequisites aspdotnet-mvc5-slides
 
Spring Framework - Core
Spring Framework - CoreSpring Framework - Core
Spring Framework - Core
 
Inter-app communication. How to share stuff between apps
Inter-app communication. How to share stuff between appsInter-app communication. How to share stuff between apps
Inter-app communication. How to share stuff between apps
 
Introduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoCIntroduction to Spring Framework and Spring IoC
Introduction to Spring Framework and Spring IoC
 
Asp.Net difference faqs- 10
Asp.Net difference faqs- 10Asp.Net difference faqs- 10
Asp.Net difference faqs- 10
 
Distributed ID generator in ChatWork
Distributed ID generator in ChatWorkDistributed ID generator in ChatWork
Distributed ID generator in ChatWork
 
Introduction to springs and controlers
Introduction to springs and controlersIntroduction to springs and controlers
Introduction to springs and controlers
 

Similar to Krazykoder struts2 spring_hibernate

Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
NourhanTarek23
 
Struts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks TogetherStruts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks Together
Syed Shahul
 
Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 intro
Krazy Koder
 

Similar to Krazykoder struts2 spring_hibernate (20)

Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2Java J2EE Interview Question Part 2
Java J2EE Interview Question Part 2
 
Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2Java J2EE Interview Questions Part 2
Java J2EE Interview Questions Part 2
 
Spring 2
Spring 2Spring 2
Spring 2
 
Spring annotations notes
Spring annotations notesSpring annotations notes
Spring annotations notes
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Spring framework Controllers and Annotations
Spring framework   Controllers and AnnotationsSpring framework   Controllers and Annotations
Spring framework Controllers and Annotations
 
Java spring ppt
Java spring pptJava spring ppt
Java spring ppt
 
141060753008 3715301
141060753008 3715301141060753008 3715301
141060753008 3715301
 
Spring Framework - III
Spring Framework - IIISpring Framework - III
Spring Framework - III
 
Spring training
Spring trainingSpring training
Spring training
 
Os Johnson
Os JohnsonOs Johnson
Os Johnson
 
Spring boot
Spring bootSpring boot
Spring boot
 
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveDataAndroid MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
Android MVVM architecture using Kotlin, Dagger2, LiveData, MediatorLiveData
 
Struts
StrutsStruts
Struts
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
 
Configuring jpa in a Spring application
Configuring jpa in a  Spring applicationConfiguring jpa in a  Spring application
Configuring jpa in a Spring application
 
Introduction to Spring sec1.pptx
Introduction to Spring sec1.pptxIntroduction to Spring sec1.pptx
Introduction to Spring sec1.pptx
 
Struts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks TogetherStruts 2 And Spring Frameworks Together
Struts 2 And Spring Frameworks Together
 
Struts
StrutsStruts
Struts
 
Krazykoder struts2 intro
Krazykoder struts2 introKrazykoder struts2 intro
Krazykoder struts2 intro
 

More from Krazy Koder (20)

2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xd
2310 b xd2310 b xd
2310 b xd
 
2310 b xc
2310 b xc2310 b xc
2310 b xc
 
2310 b xb
2310 b xb2310 b xb
2310 b xb
 
2310 b 17
2310 b 172310 b 17
2310 b 17
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 16
2310 b 162310 b 16
2310 b 16
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 15
2310 b 152310 b 15
2310 b 15
 
2310 b 14
2310 b 142310 b 14
2310 b 14
 
2310 b 13
2310 b 132310 b 13
2310 b 13
 
2310 b 12
2310 b 122310 b 12
2310 b 12
 
2310 b 11
2310 b 112310 b 11
2310 b 11
 
2310 b 10
2310 b 102310 b 10
2310 b 10
 
2310 b 09
2310 b 092310 b 09
2310 b 09
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 08
2310 b 082310 b 08
2310 b 08
 
2310 b 07
2310 b 072310 b 07
2310 b 07
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Krazykoder struts2 spring_hibernate

  • 1. Struts 2 Spring and JPA / Hibernate Integration KrazyKoder.com
  • 2. Why use Spring with Struts ?  It is a lightweight dependency injection and aspect-oriented container and framework.  Promote Loose Coupling through Dependancy Injection.  Most popular technology for managing creation of objects in a Java application.  Has its own MVC application framework. KrazyKoder.com
  • 3. Adding Spring to Struts2 Contd…..  Add the Spring plug-in to application.  Add org.springframework.web.context.ContextLoaderListener to web.xml in listener tag.  ApplicationContext.xml file will be used for doing the Spring bean configuration.  Spring Provides the autowiring mechanism through which it automatically inject dependencies without explicitly declaring the wiring in applicationContext.xml  Autowiring can be done by name, type, constructor or auto. KrazyKoder.com
  • 4. Adding Spring to Struts2 …..Contd.  All objects which spring manages are called “Spring Beans” and all spring beans are created as Singleton.  Add bean to applicationContext.xml file and change scope of bean to Prototype.  ID in first bean to identify the bean, much like a reference is used to identify an object in Java code.  Property tag looks for setter method with the same name as the property tag’s name attribute.  Value to inject into this setter is specified with the ref attribute  Ex : <bean id="portfolioService" class="manning.chapterNine.utils.PortfolioServiceJPAImpl"/> <bean id="springManagedLoginAction” class="manning.chapterNine.Login“ scope="prototype"> <property name="portfolioService" ref="portfolioService"/> KrazyKoder.com </bean>
  • 5. Adding JPA with Struts 2?  This technology, wrapped around Hibernate.  Coding to the JPA works a lot like coding to native Hibernate.  Interface-based architecture gives you the ability to switch out the vendor supplying the underlying implementation.  Shows how to use the well-respected Spring support for JPA to make management of the JPA all that much easier.  Main entry point into the JPA is EntityManager. This object manages all persistent entities. KrazyKoder.com
  • 6. Adding JPA with Struts 2?  Declare a bean postprocessor that checks all the beans managed by Spring for persistence-related annotations  EntityManagerFactory managed by Spring encapsulates most of the details of persistence unit.  Main entry point into configuring persistence unit is the persistence.xml file. /WEB-INF/classes/METAINF/persistence.xml  Through JPA we can use Java annotations to map java classes to database. KrazyKoder.com
  • 7. Done!  Click the icon at the bottom to proceed! KrazyKoder.com